define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var mater_id = $("#mater_id").val()

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'bdl/bal/inventory/index' + location.search + '&mater_id=' + mater_id,
                    multi_url: 'bdl/bal/inventory/multi?ids=' + mater_id,
                    export_url: 'bdl/bal/inventory/export?ids=' + mater_id,
                    table: 'bal_inventory',
                }
            });

            var table       = $("#table");
            var showExport  = $(".btn-export").data('value')

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                search:false,
                fixedColumns: true,
                fixedRightNumber: 1,
                showToggle: false,
                showExport: showExport,
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: 'ID',operate:false},
                        {
                            field: 'forgid', title: __('数据中心/组织'), searchList: function (column) {
                                return Template('forgidtpl', {});
                            }, formatter: function (value, row, index) {
                                return '无';
                            }, visible: false
                        },
                        {field: 'fk_bdl_bd_materialnum', title: '产品编码', operate: 'LIKE'},

                        {field: 'datacenter.fname', title: '数据中心名称',operate: false},
                        {field: 'forg.fname', title: '组织名称',operate: false},
                        {field: 'forg.fnumber', title: '组织编码',operate: false},
                        {field: 'forg.id', title: '组织ID',operate: false},

                        {field: 'fk_bdl_bd_lot', title: '批号',operate: "LIKE"},
                        {field: 'fk_bdl_bd_stock', title: '仓库',operate: "LIKE"},
                        {field: 'fk_bdl_usableqty', title: '可用量(辅单位)',operate:'BETWEEN',  autocomplete:false},
                        {field: 'inventoryentry', title: '属性值', operate: false,
                            formatter: function (value,row_data)
                            {
                                var str = "";
                                for (var i = 0; i < row_data.inventoryentryvalue.length; i++)
                                {
                                    str += row_data.inventoryentryvalue[i].fname + row_data.inventoryentryvalue[i].pivot['fk_bdl_matpropvalue'] + "*";

                                }

                                return str;
                            }
                        },

                        {field: 'fk_bdl_bd_texture', title: '材质ID',operate: false},
                        {field: 'texturefirs.fname', title: '材质名称',operate: "LIKE"},
                        {field: 'fk_bdl_bd_surface', title: '表面ID',operate: false},
                        {field: 'surfacefirs.fname', title: '表面名称',operate: "LIKE"},

                        {field: 'surface_image', title: '图片', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},


                        {field: 'fk_bdl_specification', title: '规格描述', operate: 'LIKE'},
                        {field: 'fk_bdl_unitid', title: '辅单位', operate: 'LIKE'},
                        {field: 'fk_bdl_priceunitid', title: '基本单位', operate: 'LIKE'},
                        {field: 'fk_bdl_bd_materialnum', title: '产品编码', operate: 'LIKE'},
                        {field: 'fk_bdl_keycol', title: 'fk_bdl_keycol', operate: 'LIKE'},


                        //基础数据
                        {field: 'fenable', title: '使用状态', searchList: {"1":'可用',"0":'禁用'}, formatter: Table.api.formatter.status}  ,








                        {field: 'fk_bdl_comment', title: '备注', operate: 'LIKE'},
                        {field: 'fk_bdl_creatorid', title: '创建人',visible:false,searchList: $.getJSON("bdl/bd/datacenter/getFilter?type=get_admin_list")},
                        {field: 'creator.nickname', title: '创建人', operate: false},
                        {field: 'fk_bdl_createtime', title: '创建时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'fk_bdl_fmodifierid', title: '修改人',visible:false,searchList: $.getJSON("bdl/bd/datacenter/getFilter?type=get_admin_list")},
                        {field: 'modifier.nickname', title: '修改人', operate: false},
                        {field: 'fk_bdl_modifytime', title: '修改时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false}

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };

    return Controller;
});
